﻿/**
**********************************************************************************
*   Facebook.WallPost
**********************************************************************************
*/
Facebook.WallPost = function(config) {
    this.trigger = config.trigger;
	this.user = config.user || null; // accepts a hidden field element where the value is the user id OR the field element used for MyCoverGirl.FriendSelect (if left null, defaults to current user)
    this.name = config.name;
    this.picture = config.picture;
    this.caption = config.caption;
    this.description = config.description;
    this.message = config.message;
	this.properties = config.properties || null;
	this.actions = config.actions || null;

    this.init(); // constructor call
};
Facebook.WallPost.prototype = {
    // constructor
    init: function()
    {
        // DOM element cache

        // setup methods
		this.attachEvents();
    },

    attachEvents: function()
    {
        this.trigger.live('click', $.proxy(function(event) { this.shareDialog(event) }, this));
    },

    shareDialog: function(event)
    {
		event.preventDefault();
		
		var userId = null;
		if (this.user && !this.user.data('uid')) {
			var userId = this.user.val();
		} else if (this.user && this.user.data('uid') && this.user.data('name') == this.user.val()) {
			var userId = this.user.data('uid');
		}
		
		FB.ui({
			method: 'feed'
			, to: userId
			, name: this.name
			, link: this.link
			, picture: this.picture
			, caption: this.caption
			, description: this.description
			, message: this.message
			, properties: this.properties
			, actions: this.actions
		},
		function(response) {
			if (response && response.post_id) {
				// post was published
			} else {
				// post was not published
			}
		});
    }
};
